package com.whsxt.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.whsxt.domain.Return;
import com.whsxt.dto.ReturnDto;
import com.whsxt.mapper.ReturnMapper;
import com.whsxt.service.ReturnService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class ReturnServiceImpl implements ReturnService {

    @Autowired
    private ReturnMapper returnMapper;
    /**
     * 获取租车记录的分页数据
     * @param returnDto
     * @return
     */
    @Override
    public PageInfo<Return> select(ReturnDto returnDto) {

        Page<Object> objects = PageHelper.startPage(returnDto.getPage(), returnDto.getLimit());
        List<Return> returnList = returnMapper.selectPage(returnDto);
        PageInfo<Return> returnPageInfo = new PageInfo<>(returnList);
        returnPageInfo.setTotal(objects.getTotal());
        return returnPageInfo;
    }

    /**
     * 批量删除租车记录
     * @param ids
     * @return
     */
    @Override
    public boolean batchDelete(List<Integer> ids) {
        return returnMapper.batchRemove(ids) > 0;
    }

    /**
     * 清空租车记录
     * @return
     */
    @Override
    public boolean clear() {
        return returnMapper.deleteAll() > 0;
    }
}
